import Vue from 'vue'
import VueRouter from 'vue-router'
// import LoginViews from "../views/LoginView.vue";
// import Storage from 'vue-ls'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: () => import("../views/LoginView.vue")
  },
  {
    path: '/HomeView',
    name: 'HomeView',
    component: () => import(/* webpackChunkName: "about" */ '../views/HomeView.vue'),
    children: [
      {

        path: '/UserList',
        name: 'UserList',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/User/UserList.vue'),
        meta: {
          title: "用户管理模块"
        }
      }


      ,
      {
        path: '/UserAddView',
        name: 'UserAddView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/User/UserAddView.vue'),
        meta: {
          title: "用户添加模块"
        }
      }
      ,
      {
        path: '/UserUpdView',
        name: 'UserUpdView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/User/UserUpdView.vue'),
        meta: {
          title: "用户修改模块"
        }
      }
      ,
      {
        path: '/UserRoleView',
        name: 'UserRoleView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/User/UserRoleView.vue'),
        meta: {
          title: "用户角色添加模块"
        }
      }
      ,
      {
        path: '/RoleList',
        name: 'RoleList',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Role/RoleList.vue'),
        meta: {
          title: "角色显示模块"
        }
      }
      ,
      {
        path: '/RoleAddView',
        name: 'RoleAddView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Role/RoleAddView.vue'),
        meta: {
          title: "角色添加模块"
        }
      },
      {
        path: '/RoleEditView',
        name: 'RoleEditView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Role/RoleEditView.vue'),
        meta: {
          title: "角色修改模块"
        }
      },
      {
        path: '/MenulistView',
        name: 'MenulistView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Menu/MenulistView.vue'),
        meta: {
          title: "菜单显示模块"
        }
      },
      {
        path: '/MenuAddView',
        name: 'MenuAddView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Menu/MenuAddView.vue'),
        meta: {
          title: "菜单添加模块"
        }
      },
      {
        path: '/MenuEditView',
        name: 'MenuEditView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Menu/MenuEditView.vue'),
        meta: {
          title: "菜单修改模块"
        }
      },
      {
        path: '/UserRoleListView',
        name: 'UserRoleListView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/UserRole/UserRoleListView.vue'),
        meta: {
          title: "用户角色关系显示模块"
        }
      }
      ,
      {
        path: '/UserRoleAddView',
        name: 'UserRoleAddView',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/UserRole/UserRoleAddView.vue'),
        meta: {
          title: "用户角色关系添加模块"
        }
      }
      ,
      {
        path: '/MenuList',
        name: 'MenuList',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/Menu/MenuList.vue'),
        meta: {
          title: "用户角色关系添加模块"
        }
      }
      ,
      {
        path: '/404',
        name: 'Notfound',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../NotfoundView')
      }
    ]
  }
  ,
  {
    path: '*',
    redirect: "/404",
    hidden: true
  }

]

const router = new VueRouter({
  routes
})
//路由首位
router.beforeEach((to, from, next) => {
  //  document.title = `${Defalt}-${to.meta.title}`

  let token = localStorage.getItem("token");
  if (token != null || to.path != '/LoginView') {
    next();
  } else if (token == null) {
    to.path == '/'
  } else {
    next();
  }


})


export default router
